# coding: utf-8

from itertools import tee, chain


def pairwise(iterable):
    left, right = tee(iterable)
    next(right, None)
    return zip(left, right)


def triadwise(iterable):
    left, center, right = tee(iterable, 3)
    next(center, None)
    next(right, None)
    next(right, None)
    return zip(left, center, right)


def triadwise_none(iter):
    def my_iter(origin):
        yield None
        for o in origin:
            yield o
        yield None
    return triadwise(my_iter(iter))


def flatten(listOfLists):
    return list(chain.from_iterable(listOfLists))